{% extends "admin_base.html" %}

{% block content %}
<div class="card border-0 shadow-sm">
    <div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
        <h5 class="mb-0"><i class="bi bi-credit-card me-2"></i> 银行卡管理</h5>
        <div>
            <a href="{{ url_for('add_card') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle me-1"></i> 添加银行卡
            </a>
        </div>
    </div>
    <div class="card-body">
        <!-- 搜索表单 -->
        <form class="mb-4" method="GET" action="{{ url_for('manage_cards') }}">
            <div class="row g-3">
                <div class="col-md-6">
                    <div class="input-group">
                        <input type="text" class="form-control" name="search" 
                               value="{{ search_term }}" placeholder="输入搜索内容">
                        <button class="btn btn-primary" type="submit">
                            <i class="bi bi-search"></i> 搜索
                        </button>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="col-md-3">
    <label for="type">选择搜索类型</label>
    <select class="form-select" name="type" id="type">
        <option value="card_id" {% if search_type == 'card_id' %}selected{% endif %}>按卡号</option>
        <option value="customer_id" {% if search_type == 'customer_id' %}selected{% endif %}>按客户ID</option>
        <option value="customer_name" {% if search_type == 'customer_name' %}selected{% endif %}>按客户姓名</option>
    </select>
</div>

                <div class="col-md-3">
                    <a href="{{ url_for('manage_cards') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-counterclockwise"></i> 重置
                    </a>
                </div>
            </div>
        </form>
        
        <!-- 银行卡列表 -->
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead class="table-light">
                    <tr>
                        <th>卡号</th>
                        <th>类型</th>
                        <th>客户</th>
                        <th>开户日期</th>
                        <th>余额</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for card in cards %}
                    <tr>
                        <td>{{ card.id }}</td>
                        <td>{{ card.type }}</td>
                        <td>{{ card.customer_name }} (ID: {{ card.customer_id }})</td>
                        <td>{{ card.open_date }}</td>
                        <td>¥{{ card.balance}}</td>
                        <td>
                            {% if card.loss %}
                            <span class="badge bg-danger">挂失</span>
                            {% else %}
                            <span class="badge bg-success">正常</span>
                            {% endif %}
                        </td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('edit_card', card_id=card.id) }}" 
                                   class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-pencil"></i> 编辑
                                </a>
                                <form method="POST" action="{{ url_for('delete_card', card_id=card.id) }}" 
                                      class="d-inline" onsubmit="return confirm('确定要删除该银行卡吗？');">
                                    <button type="submit" class="btn btn-sm btn-outline-danger">
                                        <i class="bi bi-trash"></i> 删除
                                    </button>
                                </form>
                                {% if not card.loss %}
                                <form method="POST" action="{{ url_for('card_loss', card_id=card.id) }}" 
                                      class="d-inline" onsubmit="return confirm('确定要挂失该银行卡吗？');">
                                    <button type="submit" class="btn btn-sm btn-outline-warning">
                                        <i class="bi bi-shield-exclamation"></i> 挂失
                                    </button>
                                </form>
                                {% endif %}
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="7" class="text-center py-4">没有找到银行卡记录</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}